package com.nzd.slsharing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nzd.slsharing.dto.UserCommentDto;
import com.nzd.slsharing.pojo.Comment;
import com.nzd.slsharing.pojo.PostSection;
import com.nzd.slsharing.pojo.Star;
import com.nzd.slsharing.pojo.User;
import com.nzd.slsharing.service.CommentService;
import com.nzd.slsharing.service.PostSectionService;
import com.nzd.slsharing.service.StarService;
import com.nzd.slsharing.service.UserService;
import com.nzd.slsharing.util.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//评论控制器
@RestController
@RequestMapping("/api/Star")
public class StarController {

    @Resource
    private StarService starService;


    //分页获取所有评论(不带分页)
    @GetMapping("/list")
    public Result findAll() {
        return Result.ok(starService.list());
    }

    //关注
    @PostMapping("/star")
    public Result star(@RequestBody Star star) {
        star.setCreateTime(new Date());
        System.out.println(star.toString());
        return Result.ok(starService.save(star));
    }


    //删除
    @DeleteMapping("/del")
    public Result del(@RequestParam(required = false, defaultValue = "") String userId,@RequestParam(required = false, defaultValue = "") String starUserId) {
        QueryWrapper<Star> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.eq("star_user_id", starUserId);
        System.out.println("用户"+userId);
        System.out.println("关注的用户"+starUserId);
        return Result.ok(starService.remove(wrapper));
    }

    //查看是否已经关注
    @GetMapping("/isStart")
    public Result isStart(@RequestParam(required = false, defaultValue = "") String userId,@RequestParam(required = false, defaultValue = "") String starUserId) {
        QueryWrapper<Star> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.eq("star_user_id", starUserId);
        System.out.println("用户"+userId);
        System.out.println("关注的用户"+starUserId);
        Integer num=starService.list(wrapper).size();
        System.out.println(num+"当前数量");
        return Result.ok(num>0?true:false);
    }
}

